

package com.hazelcast.client.test.executor.tasks;

import com.hazelcast.client.test.IdentifiedFactory;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;

import java.io.IOException;
import java.util.concurrent.Callable;

/**
 * This class is for Non-java clients as well. Please do not remove or modify.
 */
public class CancellationAwareTask implements Callable<Boolean>, IdentifiedDataSerializable {
    public static final int CLASS_ID = 6;

    private long sleepTime;

    public CancellationAwareTask() {
    }

    public CancellationAwareTask(long sleepTime) {
        this.sleepTime = sleepTime;
    }

    @Override
    public Boolean call() throws InterruptedException {
        Thread.sleep(sleepTime);
        return Boolean.TRUE;
    }

    @Override
    public int getFactoryId() {
        return IdentifiedFactory.FACTORY_ID;
    }

    @Override
    public int getClassId() {
        return CLASS_ID;
    }

    @Override
    public void writeData(ObjectDataOutput out) throws IOException {
        out.writeLong(sleepTime);
    }

    @Override
    public void readData(ObjectDataInput in) throws IOException {
        sleepTime = in.readLong();
    }
}
